package com.example.hellocharts;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.widget.SeekBar;

import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleDataSet;
import com.github.mikephil.charting.data.CandleEntry;

import java.util.ArrayList;
import java.util.List;

public class Main6Activity extends AppCompatActivity {
    private CandleStickChart chart3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main6);
        chart3 = findViewById(R.id.chart3);
        CandleDataSet dataSet=getDataset("test");
        dataSet.setShadowColor(Color.DKGRAY);
        dataSet.setShadowWidth(0.5f);
        dataSet.setDecreasingColor(Color.RED);
        dataSet.setDecreasingPaintStyle(Paint.Style.FILL);
        dataSet.setIncreasingColor(Color.rgb(122, 242, 84));
        dataSet.setIncreasingPaintStyle(Paint.Style.STROKE);
        dataSet.setNeutralColor(Color.YELLOW);
        CandleData data=new CandleData(dataSet);
        chart3.setData(data);
        chart3.invalidate();

    }
    private CandleDataSet getDataset(String title){
        List<CandleEntry> list=new ArrayList<>();
        for (int i=0;i<10;i++){
            float high=50.0f+((float)Math.random()*30f);
            float low=50.0f-((float)Math.random()*30f);
            float diff=high-low;
            float open=high - diff*0.8f*((float)Math.random());
            float close=high - diff*0.8f*((float)Math.random());
            CandleEntry entry=new CandleEntry(i,high,low,open,close);
            list.add(entry);
        }
        return new CandleDataSet(list,title);
    }
}
